package com.lhys.controller;


import com.github.pagehelper.PageInfo;
import com.lhys.common.ApiResultMsg;
import com.lhys.common.ResultInfo;
import com.lhys.controller.base.BaseController;
import com.lhys.pojo.AssetGainMode;
import com.lhys.service.AssetGainModeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 取得方式 前端控制器
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Api(tags = "取得方式模块")
@RestController
@RequestMapping("/api/asset-gainMode")
public class AssetGainModeController extends BaseController {
    @Autowired
    private AssetGainModeService assetGainModeService;

    @PutMapping("/save")
    @ApiOperation(value = "取得方式添加或更新", authorizations = {@Authorization(value = header)})
    public ApiResultMsg saveAssetGainMode(@RequestBody AssetGainMode assetGainMode) {
        Boolean aBoolean = assetGainModeService.saveAssetGainMode(assetGainMode);
        if(aBoolean == null){
            return ApiResultMsg.error("该取得方式标题或编码已存在");
        }
        if (!aBoolean) {
            return ApiResultMsg.error(ResultInfo.ERROR);
        }
        return ApiResultMsg.success(ResultInfo.SUCCESS);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "取得方式删除", authorizations = {@Authorization(value = header)})
    public ApiResultMsg deleteAssetGainMode(@PathVariable("id") Integer id) {
        Boolean aBoolean = assetGainModeService.delAssetGainModeById(id);
        if (!aBoolean) {
            return ApiResultMsg.error(ResultInfo.ERROR);
        }
        return ApiResultMsg.success(ResultInfo.SUCCESS);
    }

    @GetMapping("/getAssetGainMode/{id}")
    @ApiOperation(value = "根据id查询取得方式", authorizations = {@Authorization(value = header)})
    public ApiResultMsg getAssetGainModeById(@PathVariable("id") Integer id) {
        AssetGainMode assetGainMode = assetGainModeService.getAssetGainModeById(id);
        return ApiResultMsg.success(ResultInfo.SUCCESS, assetGainMode);
    }

    @GetMapping("/list")
    @ApiOperation(value = "取得方式查询分页", authorizations = {@Authorization(value = header)})
    public ApiResultMsg listAssetGainModeByPage(AssetGainMode assetGainMode, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<AssetGainMode> assetGainModeList = assetGainModeService.getAssetGainModeList(assetGainMode, pageNum, pageSize);
        return ApiResultMsg.success(ResultInfo.SUCCESS, assetGainModeList);
    }
}

